package com.gitee.wsl.ext.array

internal fun <T> Array<out T>.contentEquals(that: Array<T>, src: Int, dst: Int): Boolean =
    equaler(dst - src) { this[src + it] == that[src + it] }

internal fun IntArray.contentEquals(that: IntArray, src: Int, dst: Int): Boolean =
    equaler(dst - src) { this[src + it] == that[src + it] }

internal fun ShortArray.contentEquals(that: ShortArray, src: Int, dst: Int): Boolean =
    equaler(dst - src) { this[src + it] == that[src + it] }

internal fun FloatArray.contentEquals(that: FloatArray, src: Int, dst: Int): Boolean =
    equaler(dst - src) { this[src + it] == that[src + it] }

internal fun DoubleArray.contentEquals(that: DoubleArray, src: Int, dst: Int): Boolean =
    equaler(dst - src) {
        this[src + it] == that[src + it]
    } // Do not want to use Long (.toRawBits) to prevent boxing on JS

internal inline fun equaler(count: Int, gen: (index: Int) -> Boolean): Boolean {
    for (n in 0 until count) if (!gen(n)) return false
    return true
}